package com.zte.purchase.control;

import com.zte.purchase.model.CProduct;
import com.zte.purchase.model.CType;
import com.zte.purchase.model.ProductCondition;
import com.zte.purchase.server.IProductServer;
import com.zte.util.OperatorLog;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ProductAction {

    @Autowired
    private IProductServer productServer;

    @RequestMapping("/purchase/addProduct")
//    @OperatorLog(operate="添加产品", module="采购管理")
    @ResponseBody
    public ResultMessage addProduct(CProduct addProduct){
        boolean mo = productServer.addProduct(addProduct);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(mo);

        return msg;
    }

    @RequestMapping("/purchase/updateProduct")
//    @OperatorLog(operate="修改产品", module="采购管理")
    @ResponseBody
    public ResultMessage updateProduct(CProduct updateProduct){
        System.out.println(updateProduct);
        boolean mo = productServer.updateProduct(updateProduct);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(mo);

        return msg;
    }

    @RequestMapping("/purchase/findOneProduct")
    @ResponseBody
    public ResultMessage findOneProduct(String productId){
        CProduct mo = productServer.findOneProduct(productId);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(mo);

        return msg;
    }

    @RequestMapping("/purchase/queryProductPage")
//    @OperatorLog(operate="多条件分页查询产品", module="采购管理")
    @ResponseBody
    public ResultMessage queryProductPage(Integer pageNum, Integer pageSize, ProductCondition cpConn){
        PageModel<CProduct> pageModel = new PageModel<>();
        pageModel.setPageNum(pageNum);
        pageModel.setPageSize(pageSize);

        PageModel<CProduct> mo = productServer.queryProductList(pageModel, cpConn);

        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setMsg("查询成功");
        msg.setFlag(true);
        msg.setData(mo);

        return msg;
    }

}
